package graph.day04;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Kama_104 {

    static int[][] direction = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

    static int[][] graph;

    static int mark = 2;

    static int dfs(int x, int y) {
        if (x < 0 || x >= graph.length || y < 0 || y >= graph[0].length || graph[x][y] != 1) return 0;
        graph[x][y] = mark;
        int area = 1;
        for (int i = 0; i < 4; i++) {
            int nextX = x + direction[i][0];
            int nextY = y + direction[i][1];
            area += dfs(nextX, nextY);
        }
        return area;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        graph = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                graph[i][j] = sc.nextInt();
            }
        }
        int result = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 1) {
                    int area = dfs(i, j);
                    map.put(mark, area);
                    if (area > result) result = area;
                    mark++;
                }
            }
        }
        boolean[] visited = new boolean[mark];
        for (int x = 0; x < n; x++) {
            for (int y = 0; y < m; y++) {
                if (graph[x][y] == 0) {
                    int area = 1;
                    Arrays.fill(visited, false);
                    for (int i = 0; i < 4; i++) {
                        int nextX = x + direction[i][0];
                        int nextY = y + direction[i][1];
                        if (nextX < 0 || nextX >= n || nextY < 0 || nextY >= m) continue;
                        int curMark = graph[nextX][nextY];
                        if (curMark != 0 && !visited[curMark]) {
                            area += map.get(curMark);
                            visited[curMark] = true;
                        }
                    }
                    if (area > result) result = area;
                }
            }
        }
        System.out.println(result);
    }
}
